'''Node querying via the Planet Lab RPC protocol.'''

import xmlrpclib

def get_hostnames(node_slice='usf_ubcslice5'):
	auth = {'Username':"yanhero@interchange.ubc.ca", 
		'AuthString':"eece411",
		'AuthMethod':"password"}

	server = xmlrpclib.ServerProxy('https://www.planet-lab.org/PLCAPI/')

	# Get the node ids associated with our slice
	node_ids = server.GetSlices(auth, node_slice, ['node_ids'])
	node_list = node_ids[0]['node_ids']
	#print node_list

	# Get the hostname associated with each node id
	node_hostnames=[]
	for node in node_list[:]:
	   node_info = server.GetNodes(auth,node, ['boot_state', 'hostname'])
	   if len(node_info) > 0:
		#print str(node) +  ": "
		#print node_info[0]['hostname']
	   	node_hostnames.append( node_info[0]['hostname'] )

	return node_hostnames
